<?php
class logisticsmanager_task{

    function post_install($options){
        kernel::single('base_initial', 'logisticsmanager')->init();

        // 顺风城市编码
        kernel::single('logisticsmanager_citycode_sf')->install();

        $this->insertTemplate();
        $this->_addExtendWaybillTmpl();    }

    function xml_to_array( $xml )
    {
        $reg = "/<(\\w+)[^>]*?>([\\x00-\\xFF]*?)<\\/\\1>/";
        if(preg_match_all($reg, $xml, $matches))
        {
            $count = count($matches[0]);
            $arr = array();
            for($i = 0; $i < $count; $i++)
            {
                $key = $matches[1][$i];
                $val = $this->xml_to_array( $matches[2][$i] );  // 递归
                if(array_key_exists($key, $arr))
                {
                    if(is_array($arr[$key]))
                    {
                        if(!array_key_exists(0,$arr[$key]))
                        {
                            $arr[$key] = array($arr[$key]);
                        }
                    }else{
                        $arr[$key] = array($arr[$key]);
                    }
                    $arr[$key][] = $val;
                }else{
                    $arr[$key] = $val;
                }
            }
            return $arr;
        }else{
            return $xml;
        }
    }

    function unescape($str){
        $ret = '';
        $len = strlen($str);
        for ($i = 0; $i < $len; $i++){
            if ($str[$i] == '%' && $str[$i+1] == 'u'){
                $val = hexdec(substr($str, $i+2, 4));
                if ($val < 0x7f) {
                    $ret .= chr($val);
                } else if($val < 0x800) {
                    $ret .= chr(0xc0|($val>>6)).chr(0x80|($val&0x3f));
                } else {
                    $ret .= chr(0xe0|($val>>12)).chr(0x80|(($val>>6)&0x3f)).chr(0x80|($val&0x3f));
                }
                $i += 5;
            } else if ($str[$i] == '%') {
                $ret .= urldecode(substr($str, $i, 3));
                $i += 2;
            } else {
                $ret .= $str[$i];
            }
        }
        return $ret;
    }

    /**
     * 插入模板
     *
     * @return void
     * @author 
     **/
    private function insertTemplate()
    {
        $templateObj = app::get("logisticsmanager")->model("express_template");

        $tmpls = app::get("ome")->model("print_tmpl")->getList();
        if ($tmpls) {        
            foreach ($tmpls as $key => $val) {
                $tmplData = $prt_tmpl_data = array();
                $newTmplStr = $imgUrl = "";
                $width = $height = 0;

                // 转换背景,计算宽、高
                $imgUrl = kernel::single('base_storager')->getUrl($val['file_id'],"file");
                
                if ($imgUrl) {
                    list($widthImg, $heightImg) = getimagesize($imgUrl);

                    $width  = intval($widthImg*25.4/96);
                    $height = intval($heightImg*25.4/96);
                } else {
                    $width  = intval($val['prt_tmpl_width']);
                    $height = intval($val['prt_tmpl_height']);
                    $imgUrl = 'NONE';
                }

                $newTmplStr .= "paper:".$width.",".$height.",".$imgUrl.";\n";

                //解析老模板数据
                $prt_tmpl_data = $this->xml_to_array(urldecode($val['prt_tmpl_data']));
                foreach($prt_tmpl_data['printer']['item'] as $k => $v) {
                    //判断标签类型
                    if ($v['ucode'] == 'text') {
                        $newTmplStr .= "report_label:";
                        $ucode      = '';
                    } else {
                        $newTmplStr .= "report_field:";
                        $ucode      = $v['ucode'];
                    }

                    //解码标签名称和字体
                    $v['name'] = $this->unescape($v['name']);
                    $v['font'] = $this->unescape($v['font']);

                    //转换样式信息
                    $font = ($v['font']=='undefined') ? '宋体' : $this->unescape($v['font']);
                    $fontsize = intval($v['fontsize']*72*10/96);
                    switch($v['align']) {
                        case 'center' :
                            $align = 1;
                            break;
                        case 'right' :
                            $align = 2;
                            break;
                        default:
                            $align = 0;
                            break;
                    }

                    //计算标签位置
                    $position = array();
                    $position = explode(':',$v['position']);
                    $left     = number_format($position[0]/96,6);
                    $top      = number_format($position[1]/96,6);
                    $right    = number_format(($left+$position[2]/96),6);
                    $bottom   = number_format(($top+$position[3]/96),6);

                    //生成模板数据
                    $newTmplStr .= $left.",".$top.",".$right.",".$bottom.",".$v['name'].",".$ucode.",0,".$font.",".$fontsize.",".$v['border'].",".$v['italic'].",0,0,0,".$align.",0;\n";

                    unset($v);
                }

                $newTmplData = array();
                $newTmplData['template_id']     = $val['prt_tmpl_id'];
                $newTmplData['template_name']   = $val['prt_tmpl_title'];
                $newTmplData['template_type']   = 'normal';
                $newTmplData['status']          = $val['shortcut'];
                $newTmplData['template_width']  = $width;
                $newTmplData['template_height'] = $height;
                $newTmplData['file_id']         = $val['file_id'];
                $newTmplData['template_data']   = $newTmplStr;
                $templateObj->insert($newTmplData);
                unset($val);    
            }
        }


$sql = <<<EOF
INSERT INTO `sdb_logisticsmanager_express_template` (`template_name`, `template_type`, `status`, `template_width`, `template_height`, `file_id`, `template_data`) VALUES
('EMS经济', 'electron', 'true', 100, 150, 0, 'paper:100,150,NONE;\nreport_box:0.208333,0.104167,3.958333,5.885417,,,0,1,0.000000,0,0,0,16777215;\nreport_label:0.468750,0.208333,1.885417,0.666667,EMS经济快递,,0,,160,1,0,0,0,0,0,0;\nreport_label:0.364583,0.572917,1.666667,0.927083,打印时间\\colon,,0,宋体,80,0,0,0,0,0,0,0;\nreport_field:0.989583,0.572917,1.593750,0.802083,当日日期-年,date_y,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:1.302083,0.572917,1.968750,0.802083,当日日期-月,date_m,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:1.458333,0.572917,2.156250,0.729167,当日日期-日,date_d,0,Arial,100,0,0,0,0,0,0,0;\nreport_line:0.208333,0.781250,3.958333,0.781250,,,0,0.000000,0,0;\nreport_line:0.156250,1.614583,3.958333,1.614583,,,0,0.000000,0,0;\nreport_label:0.260417,0.885417,0.875000,1.125000,寄件人：,,0,,100,0,0,0,0,0,0,0;\nreport_field:0.729167,0.885417,1.572917,1.114583,发货人-姓名,dly_name,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.864583,0.833333,3.479167,1.072917,邮编：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:3.229167,0.833333,3.875000,1.104167,发货人-邮编,dly_zip,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.364583,1.145833,0.979167,1.385417,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.260417,1.406250,1.322917,1.541667,计费重量（KG）：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.864583,1.406250,3.750000,1.645833,保价金额：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.260417,1.770833,0.875000,2.010417,收件人：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.312500,2.031250,0.937500,2.270833,电话：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.312500,2.291667,0.927083,2.562500,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.656250,2.031250,3.104167,2.270833,邮编：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.500000,1.666667,3.114583,1.906250,城市：,,0,黑体,100,0,0,0,0,0,2,0;\nreport_label:0.312500,2.604167,1.406250,2.843750,收件人签名：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:1.979167,2.604167,2.666667,2.843750,签收时间：,,0,,100,0,0,0,0,0,0,0;\nreport_label:2.708333,2.604167,2.968750,2.812500,年 ,,0,,100,0,0,0,0,0,0,0;\nreport_label:3.020833,2.604167,3.281250,2.812500,月,,0,,100,0,0,0,0,0,0,0;\nreport_label:3.333333,2.604167,3.593750,2.812500,日,,0,,100,0,0,0,0,0,0,0;\nreport_label:3.645833,2.604167,3.906250,2.812500,时,,0,,100,0,0,0,0,0,0,0;\nreport_line:0.208333,2.812500,3.958333,2.812500,,,0,0.000000,0,0;\nreport_label:0.364583,2.916667,1.718750,3.125000,发货单号：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_line:0.156250,4.010417,4.031250,4.010417,,,0,11572565.333333,0,0;\nreport_label:2.135417,3.854167,3.302083,3.989583,计费重量（KG）：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.416667,4.114583,1.031250,4.354167,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_line:0.208333,4.479167,3.958333,4.479167,,,0,0.000000,0,0;\nreport_label:0.364583,4.583333,0.979167,4.822917,收件人：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.604167,4.583333,3.218750,4.822917,电话：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.468750,4.843750,1.083333,5.114583,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_line:0.208333,5.208333,3.958333,5.208333,,,0,0.000000,0,0;\nreport_label:2.447917,5.260417,2.958333,5.458333,订单号：,,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:2.395833,5.520833,2.729167,5.729167,*,,0,,160,1,0,0,0,0,0,0;\nreport_field:0.937500,3.854167,1.781250,4.083333,发货人-姓名,dly_name,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.781250,1.145833,3.947917,1.375000,发货人-详细地址,dly_detailaddr,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.833333,4.114583,3.906250,4.343750,发货人-详细地址,dly_detailaddr,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:1.197917,1.406250,2.520833,1.604167,货品重量 单位：kg,total_product_weight_kg,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.833333,1.770833,1.979167,2.000000,收货人-姓名,ship_name,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:3.072917,1.666667,3.875000,1.958333,收货人-地区2级,ship_area_1,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:0.781250,2.031250,1.927083,2.250000,收货人-手机,ship_mobile,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:3.125000,1.979167,3.770833,2.270833,收货人-邮编,ship_zip,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:0.677083,2.291667,3.604167,2.604167,收货人-详细地址,ship_detailaddr,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:3.281250,3.854167,3.906250,4.020833,货品重量 单位：kg,total_product_weight_kg,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.937500,4.583333,1.739583,4.812500,收货人-姓名,ship_name,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:3.072917,4.583333,4.072917,4.802083,收货人-手机,ship_mobile,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.937500,4.843750,3.906250,5.166667,收货人-详细地址,ship_detailaddr,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:2.916667,5.260417,3.906250,5.479167,订单-订单号,order_bn,0,黑体,80,0,0,0,0,0,0,0;\nreport_field:2.604167,5.416667,3.750000,5.833333,发货人-地区3级,dly_area_2,0,黑体,160,0,0,0,0,0,0,0;\nreport_label:0.364583,3.854167,0.979167,4.093750,寄件人：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.364583,3.385417,3.750000,3.760417,货号+货品名+数量+货位,bn_name_amount_pos,0,Arial,100,0,0,0,0,0,0,0;\nreport_barcode:2.083333,0.177083,3.927083,0.583333,123456,logi_no,0;\nreport_barcode:0.322917,5.260417,2.166667,5.666667,123456,logi_no,0;\nreport_barcode:1.072917,2.895833,3.510417,3.239583,123456,delivery_bn,0;\n'),
('EMS普通', 'electron', 'true', 100, 150, 0, 'paper:100,150,NONE;\nreport_label:0.208333,0.781250,0.822917,1.020833,寄件人：,,0,黑体,100,0,0,0,0,0,0,134;\nreport_field:0.781250,0.781250,1.625000,1.010417,发货人-姓名,dly_name,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.864583,0.729167,3.479167,0.968750,邮编：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:3.229167,0.729167,3.875000,1.000000,发货人-邮编,dly_zip,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.354167,1.041667,0.968750,1.281250,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.260417,1.333333,1.510417,1.468750,计费重量（KG）：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.864583,1.322917,3.750000,1.562500,保价金额：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.197917,1.593750,0.812500,1.833333,收件人：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.312500,1.843750,0.937500,2.083333,电话：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.312500,2.041667,0.927083,2.312500,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.656250,1.812500,3.104167,2.052083,邮编：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.500000,1.500000,3.114583,1.739583,城市：,,0,黑体,100,0,0,0,0,0,2,0;\nreport_label:0.312500,2.364583,1.406250,2.604167,收件人签名：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.052083,2.364583,2.739583,2.604167,签收时间：,,0,,100,0,0,0,0,0,0,0;\nreport_label:2.812500,2.354167,3.072917,2.562500,年 ,,3,,100,0,0,0,0,0,0,0;\nreport_label:3.072917,2.354167,3.333333,2.562500,月,,3,,100,0,0,0,0,0,0,0;\nreport_label:3.333333,2.354167,3.593750,2.562500,日,,3,,100,0,0,0,0,0,0,0;\nreport_label:3.645833,2.354167,3.906250,2.562500,时,,3,,100,0,0,0,0,0,0,0;\nreport_label:0.291667,2.625000,1.645833,2.833333,发货单号：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.125000,3.687500,3.291667,3.822917,计费重量（KG）：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.395833,3.906250,1.010417,4.145833,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.333333,4.270833,0.947917,4.510417,收件人：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.500000,4.270833,3.114583,4.510417,电话：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.468750,4.510417,1.083333,4.781250,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.916667,4.989583,3.427083,5.166667,订单号：,,1,黑体,80,0,0,0,0,0,0,0;\nreport_label:0.291667,5.520833,0.625000,5.729167,*,,0,,160,1,0,0,0,0,0,0;\nreport_field:0.875000,3.687500,1.718750,3.916667,发货人-姓名,dly_name,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.781250,1.041667,3.947917,1.270833,发货人-详细地址,dly_detailaddr,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.843750,3.927083,3.916667,4.291667,发货人-详细地址,dly_detailaddr,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:1.281250,1.343750,2.604167,1.541667,货品重量 单位：kg,total_product_weight_kg,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.833333,1.604167,1.979167,1.833333,收货人-姓名,ship_name,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:3.072917,1.500000,3.875000,1.791667,收货人-地区2级,ship_area_1,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:0.781250,1.833333,1.927083,2.052083,收货人-手机,ship_mobile,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:3.125000,1.812500,3.770833,2.104167,收货人-邮编,ship_zip,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:0.677083,2.041667,3.604167,2.354167,收货人-详细地址,ship_detailaddr,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:3.291667,3.687500,3.916667,3.854167,货品重量 单位：kg,total_product_weight_kg,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.958333,4.270833,1.760417,4.500000,收货人-姓名,ship_name,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:2.958333,4.270833,3.833333,4.489583,收货人-手机,ship_mobile,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.958333,4.562500,3.791667,4.885417,收货人-详细地址,ship_detailaddr,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:3.000000,5.125000,3.989583,5.343750,订单-订单号,order_bn,1,黑体,80,0,0,0,0,0,0,0;\nreport_field:0.447917,5.468750,2.312500,5.718750,发货人-地区3级,dly_area_2,0,黑体,160,0,0,0,0,0,0,0;\nreport_label:0.250000,3.687500,0.864583,3.927083,寄件人：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_barcode:2.291667,0.062500,3.885417,0.562500,123456,logi_no,0;\nreport_barcode:0.614583,4.947917,2.520833,5.447917,123456,logi_no,0;\nreport_barcode:0.958333,2.552083,2.864583,3.020833,123456,delivery_bn,0;\nreport_field:0.843750,0.500000,1.864583,0.729167,当日日期-年月日,date_ymd,0,Arial,100,0,0,0,0,0,0,0;\nreport_label:0.270833,0.500000,0.937500,0.687500,打印时间：,,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:2.791667,5.395833,4.947917,5.645833,网店名称,shop_name,0,Arial,120,0,0,0,0,0,0,0;\nreport_field:0.343750,2.989583,3.802083,3.479167,货号+货品名+数量(不换行),bn_name_amount_n,0,Arial,100,0,0,0,0,0,0,0;\n'),
('顺丰', 'electron', 'true', 100, 150, 0, 'paper:100,150,NONE;\nreport_label:0.239583,0.260417,1.645833,0.604167,顺丰速运,,0,黑体,200,0,0,0,0,0,0,0;\nreport_field:2.864583,0.343750,3.833333,0.593750,当日日期-年月日,date_ymd,0,Arial,100,0,0,0,0,0,1,0;\nreport_line:0.000000,0.697917,4.281250,0.697917,,,0,0.000000,0,0;\nreport_line:0.000000,1.437500,4.260417,1.437500,,,0,0.000000,0,0;\nreport_label:0.104167,0.781250,0.552083,0.947917,寄件：,,0,黑体,80,0,0,0,0,0,0,134;\nreport_field:1.739583,0.760417,2.822917,0.927083,发货人-手机,dly_mobile,0,Arial,80,0,0,0,0,0,0,0;\nreport_field:0.468750,0.770833,1.583333,0.958333,发货人-姓名,dly_name,0,Arial,80,0,0,0,0,0,0,0;\nreport_field:0.114583,0.989583,2.739583,1.229167,发货人-详细地址,dly_detailaddr,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:0.114583,1.239583,0.843750,1.437500,发货人-地区1级,dly_area_0,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:0.781250,1.239583,1.687500,1.395833,发货人-地区2级,dly_area_1,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:1.406250,1.239583,2.333333,1.437500,发货人-邮编,dly_zip,0,Arial,100,0,0,0,0,0,0,0;\nreport_line:2.875000,0.708333,2.875000,1.395833,,,0,0.000000,0,0;\nreport_label:0.093750,1.500000,0.541667,1.666667,收件：,,0,黑体,90,0,0,0,0,0,0,134;\nreport_field:0.437500,1.510417,1.166667,1.677083,收货人-姓名,ship_name,0,黑体,90,0,0,0,0,0,0,0;\nreport_field:1.677083,1.510417,3.010417,1.708333,收货人-手机,ship_mobile,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:0.125000,1.697917,4.000000,1.979167,收货人-详细地址,ship_detailaddr,0,黑体,90,0,0,0,0,0,0,0;\nreport_field:0.125000,2.000000,1.041667,2.166667,收货人-地区1级,ship_area_0,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:0.968750,2.000000,1.927083,2.197917,收货人-地区2级,ship_area_1,0,Arial,100,0,0,0,0,0,0,0;\nreport_line:0.000000,2.197917,4.333333,2.197917,,,0,0.000000,0,0;\nreport_barcode:0.260417,2.250000,2.489583,2.843750,123456,logi_no,0;\nreport_line:2.927083,2.208333,2.927083,2.937500,,,0,0.000000,0,0;\nreport_label:3.114583,2.270833,3.739583,2.583333,标快,,0,黑体,160,0,0,0,0,0,0,0;\nreport_field:3.083333,2.541667,3.854167,2.781250,货品重量 单位：kg,total_product_weight_kg,0,黑体,100,0,0,0,0,0,0,0;\nreport_line:0.000000,2.937500,4.354167,2.937500,,,0,0.000000,0,0;\nreport_label:0.145833,2.968750,1.177083,3.104167,付款方式：寄付,,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:2.364583,3.031250,3.114583,3.270833,收方签署：,,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:2.427083,3.250000,2.864583,3.406250,日期：,,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:3.020833,3.229167,3.270833,3.406250,月,,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:3.343750,3.229167,3.593750,3.406250,日,,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:3.677083,3.229167,3.927083,3.406250,时,,0,黑体,80,0,0,0,0,0,0,0;\nreport_field:1.937500,1.989583,2.625000,2.177083,收货人-邮编,ship_zip,0,Arial,100,0,0,0,0,0,0,0;\nreport_barcode:0.062500,3.822917,2.291667,4.416667,123456,logi_no,0;\nreport_line:0.000000,5.791667,0.000000,5.791667,,,0,0.000000,0,0;\nreport_label:2.468750,3.802083,2.979167,3.947917,寄件：,,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:2.750000,3.802083,3.958333,4.072917,发货人-姓名,dly_name,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:2.447917,4.104167,4.322917,4.333333,发货人-详细地址,dly_detailaddr,0,Arial,80,0,0,0,0,0,0,0;\nreport_field:2.708333,3.937500,4.708333,4.156250,发货人-手机,dly_mobile,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:2.395833,4.395833,2.958333,4.593750,发货人-地区1级,dly_area_0,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:2.802083,4.406250,3.489583,4.562500,发货人-地区2级,dly_area_1,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:3.437500,4.416667,3.885417,4.614583,发货人-邮编,dly_zip,0,Arial,100,0,0,0,0,0,0,0;\nreport_label:0.062500,4.729167,0.510417,4.895833,收件：,,0,黑体,80,0,0,0,0,0,0,134;\nreport_field:0.385417,4.739583,1.114583,4.906250,收货人-姓名,ship_name,0,黑体,80,0,0,0,0,0,0,0;\nreport_field:1.187500,4.739583,2.260417,4.937500,收货人-手机,ship_mobile,0,黑体,80,0,0,0,0,0,0,0;\nreport_field:0.125000,4.916667,1.927083,5.239583,收货人-详细地址,ship_detailaddr,0,黑体,80,0,0,0,0,0,0,0;\nreport_field:0.104167,5.218750,0.822917,5.385417,收货人-地区1级,ship_area_0,0,Arial,90,0,0,0,0,0,0,0;\nreport_field:0.583333,5.208333,1.333333,5.406250,收货人-地区2级,ship_area_1,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:0.093750,5.406250,4.041667,5.718750,货品名+规格+数量,name_spec_amount,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:1.312500,5.208333,1.968750,5.395833,收货人-邮编,ship_zip,0,Arial,100,0,0,0,0,0,0,0;\nreport_barcode:1.958333,4.791667,3.833333,5.427083,123456,delivery_bn,0;\nreport_field:2.947917,0.489583,4.958333,0.593750,打印批次号,print_no,0,Arial,100,0,0,0,0,0,0,0;\n'),
('宅急送', 'electron', 'true', 100, 150, 0, 'paper:100,150,NONE;\nreport_label:0.208333,0.781250,0.822917,1.020833,寄件人：,,0,黑体,100,0,0,0,0,0,0,134;\nreport_field:0.781250,0.781250,1.625000,1.010417,发货人-姓名,dly_name,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.864583,0.729167,3.479167,0.968750,邮编：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:3.229167,0.729167,3.875000,1.000000,发货人-邮编,dly_zip,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.354167,1.041667,0.968750,1.281250,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.260417,1.333333,1.510417,1.468750,计费重量（KG）：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.864583,1.322917,3.750000,1.562500,保价金额：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.197917,1.593750,0.812500,1.833333,收件人：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.312500,1.843750,0.937500,2.083333,电话：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.312500,2.041667,0.927083,2.312500,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.656250,1.812500,3.104167,2.052083,邮编：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.500000,1.500000,3.114583,1.739583,城市：,,0,黑体,100,0,0,0,0,0,2,0;\nreport_label:0.312500,2.364583,1.406250,2.604167,收件人签名：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.052083,2.364583,2.739583,2.604167,签收时间：,,0,,100,0,0,0,0,0,0,0;\nreport_label:2.812500,2.354167,3.072917,2.562500,年 ,,3,,100,0,0,0,0,0,0,0;\nreport_label:3.072917,2.354167,3.333333,2.562500,月,,3,,100,0,0,0,0,0,0,0;\nreport_label:3.333333,2.354167,3.593750,2.562500,日,,3,,100,0,0,0,0,0,0,0;\nreport_label:3.645833,2.354167,3.906250,2.562500,时,,3,,100,0,0,0,0,0,0,0;\nreport_label:0.291667,2.625000,1.645833,2.833333,发货单号：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.125000,3.687500,3.291667,3.822917,计费重量（KG）：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.395833,3.906250,1.010417,4.145833,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.333333,4.270833,0.947917,4.510417,收件人：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.500000,4.270833,3.114583,4.510417,电话：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.468750,4.510417,1.083333,4.781250,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.916667,4.989583,3.427083,5.166667,订单号：,,1,黑体,80,0,0,0,0,0,0,0;\nreport_label:0.291667,5.520833,0.625000,5.729167,*,,0,,160,1,0,0,0,0,0,0;\nreport_field:0.875000,3.687500,1.718750,3.916667,发货人-姓名,dly_name,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.781250,1.041667,3.947917,1.270833,发货人-详细地址,dly_detailaddr,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.843750,3.927083,3.916667,4.291667,发货人-详细地址,dly_detailaddr,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:1.281250,1.343750,2.604167,1.541667,货品重量 单位：kg,total_product_weight_kg,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.833333,1.604167,1.979167,1.833333,收货人-姓名,ship_name,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:3.072917,1.500000,3.875000,1.791667,收货人-地区2级,ship_area_1,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:0.781250,1.833333,1.927083,2.052083,收货人-手机,ship_mobile,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:3.125000,1.812500,3.770833,2.104167,收货人-邮编,ship_zip,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:0.677083,2.041667,3.604167,2.354167,收货人-详细地址,ship_detailaddr,0,黑体,100,1,0,0,0,0,0,0;\nreport_field:3.291667,3.687500,3.916667,3.854167,货品重量 单位：kg,total_product_weight_kg,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.958333,4.270833,1.760417,4.500000,收货人-姓名,ship_name,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:2.958333,4.270833,3.833333,4.489583,收货人-手机,ship_mobile,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.958333,4.562500,3.791667,4.885417,收货人-详细地址,ship_detailaddr,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:3.000000,5.125000,3.989583,5.343750,订单-订单号,order_bn,1,黑体,80,0,0,0,0,0,0,0;\nreport_field:0.447917,5.468750,2.312500,5.718750,发货人-地区3级,dly_area_2,0,黑体,160,0,0,0,0,0,0,0;\nreport_label:0.250000,3.687500,0.864583,3.927083,寄件人：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_barcode:2.291667,0.062500,3.885417,0.562500,123456,logi_no,0;\nreport_barcode:0.614583,4.947917,2.520833,5.447917,123456,logi_no,0;\nreport_barcode:0.958333,2.552083,2.864583,3.020833,123456,delivery_bn,0;\nreport_field:0.843750,0.500000,1.864583,0.729167,当日日期-年月日,date_ymd,0,Arial,100,0,0,0,0,0,0,0;\nreport_label:0.270833,0.500000,0.937500,0.687500,打印时间：,,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:2.791667,5.395833,4.947917,5.645833,网店名称,shop_name,0,Arial,120,0,0,0,0,0,0,0;\nreport_field:0.343750,2.989583,3.802083,3.479167,货号+货品名+数量(不换行),bn_name_amount_n,0,Arial,100,0,0,0,0,0,0,0;\nreport_label:0.302083,0.166667,1.489583,0.406250,宅急送,,0,Arial,160,1,0,0,0,0,0,0;\n'),
('京东电子面单', 'electron', 'true', 100, 113, 0, 'paper:0,0,NONE;\nreport_barcode:0.562500,0.145833,3.604167,0.697917,12345-1-1-,logi_no,0,1;\nreport_label:0.229167,0.760417,1.041667,0.937500,收方信息,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.229167,0.937500,0.729167,1.114583,姓名：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:1.593750,0.916667,2.072917,1.093750,电话：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.625000,0.947917,1.541667,1.145833,收货人-姓名,ship_name,0,黑体,80,0,0,0,0,0,0,0;\nreport_field:1.937500,0.937500,2.979167,1.166667,收货人-手机,ship_mobile,0,黑体,90,0,0,0,0,0,0,0;\nreport_label:0.218750,1.156250,0.833333,1.333333,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.583333,1.166667,1.166667,1.354167,收货人-地区1级,ship_area_0,0,黑体,80,0,0,0,0,0,0,0;\nreport_field:1.197917,1.156250,1.833333,1.312500,收货人-地区2级,ship_area_1,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:1.635417,1.145833,2.458333,1.322917,收货人-地区3级,ship_area_2,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:0.250000,1.343750,3.114583,1.635417,收货人-详细地址,ship_detailaddr,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.947917,0.770833,3.875000,0.947917,代收金额,,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:3.145833,1.395833,3.791667,1.635417,1/1,,0,黑体,120,0,0,0,0,0,0,0;\nreport_label:0.229167,1.625000,0.843750,1.802083,寄方信息,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.218750,1.833333,0.833333,2.010417,姓名：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.614583,1.843750,1.510417,2.052083,发货人-姓名,dly_name,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:1.635417,1.812500,2.125000,1.989583,电话：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:2.000000,1.822917,2.864583,2.041667,发货人-手机,dly_mobile,0,黑体,90,0,0,0,0,0,0,0;\nreport_label:0.218750,2.052083,0.833333,2.229167,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.635417,2.072917,2.781250,2.416667,发货人-详细地址,dly_detailaddr,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:2.958333,1.833333,3.781250,2.010417,客户签字,,0,黑体,120,0,0,0,0,0,0,0;\nreport_field:2.395833,2.322917,3.458333,2.541667,当日日期-年月日,date_ymd,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:1.250000,2.531250,2.114583,2.729167,运单号：,,0,黑体,120,0,0,0,0,0,0,0;\nreport_label:0.229167,2.854167,0.843750,3.000000,订单号：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.718750,2.854167,3.250000,3.062500,订单-订单号,order_bn,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:0.229167,3.052083,0.843750,3.229167,姓名：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.635417,3.052083,1.395833,3.239583,收货人-姓名,ship_name,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:1.552083,3.031250,2.166667,3.208333,电话：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:1.916667,3.041667,2.864583,3.291667,收货人-手机,ship_mobile,0,黑体,90,0,0,0,0,0,0,0;\nreport_label:0.218750,3.270833,0.833333,3.447917,备注：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.625000,3.291667,2.625000,3.666667,卖家备注,order_memo,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:0.250000,3.604167,0.864583,3.781250,寄方信息,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.229167,3.802083,0.843750,3.979167,姓名：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.593750,3.812500,1.406250,4.020833,发货人-姓名,dly_name,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:1.614583,3.791667,2.104167,3.968750,电话：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:1.968750,3.802083,2.979167,4.020833,发货人-手机,dly_mobile,0,黑体,90,0,0,0,0,0,0,0;\nreport_label:0.260417,4.000000,0.875000,4.177083,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.656250,4.010417,2.802083,4.354167,发货人-详细地址,dly_detailaddr,0,黑体,80,0,0,0,0,0,0,0;\nreport_field:2.354167,4.187500,3.416667,4.406250,当日日期-年月日,date_ymd,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:2.958333,2.895833,3.885417,3.072917,代收金额,,0,黑体,120,0,0,0,0,0,0,0;\nreport_field:1.937500,2.552083,3.729167,2.802083,快递单号,logi_no,0,黑体,90,0,0,0,0,0,0,0;\nreport_field:2.895833,3.166667,3.583333,3.531250,快递单-应收款,delivery_receivable,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:2.875000,0.979167,3.593750,1.302083,快递单-应收款,delivery_receivable,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:3.520833,1.000000,3.822917,1.250000,元,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:3.520833,3.197917,3.822917,3.447917,元,,0,黑体,100,0,0,0,0,0,0,0;\n'),
('京东货到付款电子', 'electron', 'true', 100, 113, 0, 'paper:0,0,NONE;\nreport_barcode:0.562500,0.145833,3.604167,0.697917,12345-1-1-,logi_no,0,1;\nreport_label:0.229167,0.760417,1.041667,0.937500,收方信息,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.229167,0.937500,0.729167,1.114583,姓名：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:1.593750,0.916667,2.072917,1.093750,电话：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.625000,0.947917,1.541667,1.145833,收货人-姓名,ship_name,0,黑体,80,0,0,0,0,0,0,0;\nreport_field:1.937500,0.937500,2.979167,1.166667,收货人-手机,ship_mobile,0,黑体,90,0,0,0,0,0,0,0;\nreport_label:0.218750,1.156250,0.833333,1.333333,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.583333,1.166667,1.166667,1.354167,收货人-地区1级,ship_area_0,0,黑体,80,0,0,0,0,0,0,0;\nreport_field:1.197917,1.156250,1.833333,1.312500,收货人-地区2级,ship_area_1,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:1.635417,1.145833,2.458333,1.322917,收货人-地区3级,ship_area_2,0,Arial,100,0,0,0,0,0,0,0;\nreport_field:0.250000,1.343750,3.114583,1.635417,收货人-详细地址,ship_detailaddr,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:2.947917,0.770833,3.875000,0.947917,代收金额,,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:3.145833,1.395833,3.791667,1.635417,1/1,,0,黑体,120,0,0,0,0,0,0,0;\nreport_label:0.229167,1.625000,0.843750,1.802083,寄方信息,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.218750,1.833333,0.833333,2.010417,姓名：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.614583,1.843750,1.510417,2.052083,发货人-姓名,dly_name,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:1.635417,1.812500,2.125000,1.989583,电话：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:2.000000,1.822917,2.864583,2.041667,发货人-手机,dly_mobile,0,黑体,90,0,0,0,0,0,0,0;\nreport_label:0.218750,2.052083,0.833333,2.229167,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.635417,2.072917,2.781250,2.416667,发货人-详细地址,dly_detailaddr,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:2.958333,1.833333,3.781250,2.010417,客户签字,,0,黑体,120,0,0,0,0,0,0,0;\nreport_field:2.395833,2.322917,3.458333,2.541667,当日日期-年月日,date_ymd,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:1.250000,2.531250,2.114583,2.729167,运单号：,,0,黑体,120,0,0,0,0,0,0,0;\nreport_label:0.229167,2.854167,0.843750,3.000000,订单号：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.718750,2.854167,3.250000,3.062500,订单-订单号,order_bn,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:0.229167,3.052083,0.843750,3.229167,姓名：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.635417,3.052083,1.395833,3.239583,收货人-姓名,ship_name,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:1.552083,3.031250,2.166667,3.208333,电话：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:1.916667,3.041667,2.864583,3.291667,收货人-手机,ship_mobile,0,黑体,90,0,0,0,0,0,0,0;\nreport_label:0.218750,3.270833,0.833333,3.447917,备注：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.625000,3.291667,2.625000,3.666667,卖家备注,order_memo,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:0.250000,3.604167,0.864583,3.781250,寄方信息,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:0.229167,3.802083,0.843750,3.979167,姓名：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.593750,3.812500,1.406250,4.020833,发货人-姓名,dly_name,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:1.614583,3.791667,2.104167,3.968750,电话：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:1.968750,3.802083,2.979167,4.020833,发货人-手机,dly_mobile,0,黑体,90,0,0,0,0,0,0,0;\nreport_label:0.260417,4.000000,0.875000,4.177083,地址：,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:0.656250,4.010417,2.802083,4.354167,发货人-详细地址,dly_detailaddr,0,黑体,80,0,0,0,0,0,0,0;\nreport_field:2.354167,4.187500,3.416667,4.406250,当日日期-年月日,date_ymd,0,黑体,80,0,0,0,0,0,0,0;\nreport_label:2.958333,2.895833,3.885417,3.072917,代收金额,,0,黑体,120,0,0,0,0,0,0,0;\nreport_field:1.937500,2.552083,3.729167,2.802083,快递单号,logi_no,0,黑体,90,0,0,0,0,0,0,0;\nreport_label:3.520833,1.000000,3.822917,1.250000,元,,0,黑体,100,0,0,0,0,0,0,0;\nreport_label:3.520833,3.197917,3.822917,3.447917,元,,0,黑体,100,0,0,0,0,0,0,0;\nreport_field:2.718750,0.979167,3.552083,1.270833,快递单-总价,delivery_order_amount,0,黑体,100,0,0,0,0,0,1,0;\nreport_field:2.791667,3.166667,3.625000,3.458333,快递单-总价,delivery_order_amount,0,黑体,100,0,0,0,0,0,1,0;\n');
EOF;

        kernel::database()->exec($sql);
    }

    //初始化电子面单模板
    private function _addExtendWaybillTmpl(){
        $dlytpl_dir = ROOT_DIR."/app/logisticsmanager/initial/tpl/";

        if($handle = opendir($dlytpl_dir)){
            while(false !== ($dtp = readdir($handle))){
                $path_parts = pathinfo($dtp);
                if($path_parts['extension'] == 'dtp'){
                    $file['tmp_name'] = $dlytpl_dir.$dtp;
                    $file['name'] = $dtp;
                    $result = kernel::single('logisticsmanager_print_tmpl')->upload_tmpl($file);
                }
            }
            closedir($handle);
        }
    }
}
